<?php
//Connection statement
require_once('../Connections/cn.php');

//MX Widgets3 include
require_once('../includes/wdg/WDG.php');

// Load the common classes
require_once('../includes/common/KT_common.php');

// Load the tNG classes
require_once('../includes/tng/tNG.inc.php');

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("../");

// Start trigger
$formValidation = new tNG_FormValidation();
$formValidation->addField("id_usuario", true, "numeric", "", "", "", "Please enter a valid value.");
$formValidation->addField("id_privilegio", true, "numeric", "", "", "", "Please enter a valid value.");
$formValidation->addField("fecha_concede_privilegio", true, "date", "datetime", "", "", "Please enter a valid value.");
$formValidation->addField("fecha_expira_privilegio", true, "date", "datetime", "", "", "Please enter a valid value.");
$tNGs->prepareValidation($formValidation);
// End trigger

// begin Recordset
$query_rs_persona = "SELECT    public.persona.rut_persona,   public.persona.nombre_persona || ' ' || public.persona.paterno_persona AS usuario FROM   public.persona   INNER JOIN public.usuario ON (public.persona.rut_persona = public.usuario.rut_persona) WHERE   (public.usuario.id_nivelusuario = 2)";
$rs_persona = $cn->SelectLimit($query_rs_persona) or die($cn->ErrorMsg());
$totalRows_rs_persona = $rs_persona->RecordCount();
// end Recordset

// begin Recordset
$query_rs_tipoprivilegio = "SELECT * FROM tipoprivilegio";
$rs_tipoprivilegio = $cn->SelectLimit($query_rs_tipoprivilegio) or die($cn->ErrorMsg());
$totalRows_rs_tipoprivilegio = $rs_tipoprivilegio->RecordCount();
// end Recordset

// Make an insert transaction instance
$ins_privilegio = new tNG_insert($cn);
$tNGs->addTransaction($ins_privilegio);
// Register triggers
$ins_privilegio->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
$ins_privilegio->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
// Add columns
$ins_privilegio->setTable("privilegio");
$ins_privilegio->addColumn("id_usuario", "NUMERIC_TYPE", "POST", "id_usuario");
$ins_privilegio->addColumn("id_privilegio", "NUMERIC_TYPE", "POST", "id_privilegio");
$ins_privilegio->addColumn("fecha_concede_privilegio", "DATE_TYPE", "POST", "fecha_concede_privilegio");
$ins_privilegio->addColumn("fecha_expira_privilegio", "DATE_TYPE", "POST", "fecha_expira_privilegio");
$ins_privilegio->setPrimaryKey("id_usuario", "NUMERIC_TYPE");

// Make an instance of the transaction object
$del_privilegio = new tNG_delete($cn);
$tNGs->addTransaction($del_privilegio);
// Register triggers
$del_privilegio->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "GET", "id_privilegio");
// Add columns
$del_privilegio->setTable("privilegio");
$del_privilegio->setPrimaryKey("id_privilegio", "NUMERIC_TYPE", "GET", "id_privilegio");

// Execute all the registered transactions
$tNGs->executeTransactions();

// Get the transaction recordset
$rsprivilegio = $tNGs->getRecordset("privilegio");
$totalRows_rsprivilegio = $rsprivilegio->RecordCount();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php //PHP ADODB document - made with PHAkt 3.6.0?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wdg="http://www.interaktonline.com/MXWidgets">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="../includes/common/js/base.js" type="text/javascript"></script>
<script src="../includes/common/js/utility.js" type="text/javascript"></script>
<script src="../includes/skins/style.js" type="text/javascript"></script>
<?php echo $tNGs->displayValidationRules();?>
<script type="text/javascript" src="../includes/common/js/sigslot_core.js"></script>
<script type="text/javascript" src="../includes/wdg/classes/MXWidgets.js"></script>
<script type="text/javascript" src="../includes/wdg/classes/MXWidgets.js.php"></script>
<script type="text/javascript" src="../includes/wdg/classes/Calendar.js"></script>
<script type="text/javascript" src="../includes/wdg/classes/SmartDate.js"></script>
<script type="text/javascript" src="../includes/wdg/calendar/calendar_stripped.js"></script>
<script type="text/javascript" src="../includes/wdg/calendar/calendar-setup_stripped.js"></script>
<script src="../includes/resources/calendar.js"></script>
</head>

<body>
<?php
	echo $tNGs->getErrorMsg();
?>
<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
  <table cellpadding="2" cellspacing="0" class="KT_tngtable">
    <tr>
      <td class="KT_th"><label for="id_usuario">Id_usuario:</label></td>
      <td><select name="id_usuario" id="id_usuario">
        <?php
  while(!$rs_persona->EOF){
?>
        <option value="<?php echo $rs_persona->Fields('rut_persona')?>"<?php if (!(strcmp($rs_persona->Fields('rut_persona'), $rsprivilegio->Fields('id_usuario')))) {echo "SELECTED";} ?>><?php echo $rs_persona->Fields('usuario')?></option>
        <?php
    $rs_persona->MoveNext();
  }
  $rs_persona->MoveFirst();
?>
      </select>
          <?php echo $tNGs->displayFieldError("privilegio", "id_usuario"); ?> </td>
    </tr>
    <tr>
      <td class="KT_th"><label for="id_privilegio">Id_privilegio:</label></td>
      <td><select name="id_privilegio" id="id_privilegio">
        <?php
  while(!$rs_tipoprivilegio->EOF){
?>
        <option value="<?php echo $rs_tipoprivilegio->Fields('id_privilegio')?>"<?php if (!(strcmp($rs_tipoprivilegio->Fields('id_privilegio'), $rsprivilegio->Fields('id_privilegio')))) {echo "SELECTED";} ?>><?php echo $rs_tipoprivilegio->Fields('describe_privilegio')?></option>
        <?php
    $rs_tipoprivilegio->MoveNext();
  }
  $rs_tipoprivilegio->MoveFirst();
?>
      </select>
          <?php echo $tNGs->displayFieldError("privilegio", "id_privilegio"); ?> </td>
    </tr>
    <tr>
      <td class="KT_th"><label for="fecha_concede_privilegio">Fecha_concede_privilegio:</label></td>
      <td><input name="fecha_concede_privilegio" id="fecha_concede_privilegio" value="<?php echo KT_formatDate($rsprivilegio->Fields('fecha_concede_privilegio')); ?>" size="32" wdg:mondayfirst="true" wdg:subtype="Calendar" wdg:mask="<?php echo $KT_screen_date_format.' '.$KT_screen_time_format; ?>" wdg:type="widget" wdg:singleclick="true" wdg:restricttomask="yes" />
      <?php echo $tNGs->displayFieldHint("fecha_concede_privilegio");?> <?php echo $tNGs->displayFieldError("privilegio", "fecha_concede_privilegio"); ?> </td>
    </tr>
    <tr>
      <td class="KT_th"><label for="fecha_expira_privilegio">Fecha_expira_privilegio:</label></td>
      <td><input name="fecha_expira_privilegio" id="fecha_expira_privilegio" value="<?php echo KT_formatDate($rsprivilegio->Fields('fecha_expira_privilegio')); ?>" size="32" wdg:mondayfirst="true" wdg:subtype="Calendar" wdg:mask="<?php echo $KT_screen_date_format.' '.$KT_screen_time_format; ?>" wdg:type="widget" wdg:singleclick="true" wdg:restricttomask="yes" />
          <?php echo $tNGs->displayFieldHint("fecha_expira_privilegio");?> <?php echo $tNGs->displayFieldError("privilegio", "fecha_expira_privilegio"); ?> </td>
    </tr>
    <tr class="KT_buttons">
      <td colspan="2"><input type="submit" name="KT_Insert1" id="KT_Insert1" value="Insertar registro" />      </td>
    </tr>
  </table>
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
$rs_persona->Close();

$rs_tipoprivilegio->Close();
?>
